<?
include_once("./_common.php");
header("Content-type: text/xml");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

if (iconv("cp949", "cp949", $q) == $q)
    $q = iconv("cp949", "utf-8", $q);

echo "<items>\n";
if ($q) {
    $any = "";
    if ($like)
        $any = "%";
    
    $sql = " select itemName, count(*) as cnt from g4_write_buyitem ";
    $sql .= " where 1 ";
    $sql .= " and itemName like '".$any.$q."%' ";
    $sql .= " group by itemName ";
    $sql .= " order by cnt desc, itemName ";
    $sql .= " limit 10 ";
    $result = sql_query($sql);
    for($i=0;$row=sql_fetch_array($result);$i++) {
        if ($i>0)
            $javascript_object .= ",";
        $s = stripslashes(strip_tags($row[itemName]));
        $s = str_replace("[", "", $s);
        $s = str_replace("]", "", $s);
        $s = str_replace("\n", "", $s);
        $s = str_replace("\r", "", $s);
        $str = iconv("utf-8", "cp949", $s);
        $str = $s;
        echo "<item>$str</item>\n";
    }
}
echo "</items>";
?>